#include "gdn/Utility.h"
#include <SFML/Graphics.hpp>
#include <iostream>

namespace gdn
{
	sf::Color ConvertFromGdn( const Color& col )
	{
return sf::Color( col.r, col.g, col.b, col.a );;
	}

	Color ConvertToGdn( const sf::Color& col )
	{
		return Color( col.r, col.g, col.b, col.a );
	}

	Event ConvertToGdn( const sf::Event& event )
	{
		if ( event.Type == sf::Event::Closed )
		{
			return Event( Event::WindowClosed );
		}
		else if ( event.Type == sf::Event::Resized )
		{
			Vector2f size;
			size.x = event.Size.Width;
			size.y = event.Size.Height;
			return Event( Event::WindowResized, size );
		}
		else if ( event.Type == sf::Event::LostFocus )
		{
			return Event( Event::WindowLostFocus );
		}
		else if ( event.Type == sf::Event::GainedFocus )
		{
			return Event( Event::WindowGainedFocus );
		}

		else if ( event.Type == sf::Event::TextEntered )
		{
			return Event( Event::TextEntered, ConvertToGdn( event.Text.Unicode ) );
		}
		else if ( event.Type == sf::Event::KeyPressed )
		{
			return Event( Event::KeyPressed, ConvertToGdn( event.Key.Code ) );
		}
		else if ( event.Type == sf::Event::KeyReleased )
		{
			return Event( Event::KeyReleased, ConvertToGdn( event.Key.Code ) );
		}

		else if ( event.Type == sf::Event::MouseMoved )
		{
			Vector2f pos;
			pos.x = event.MouseMove.X;
			pos.y = event.MouseMove.Y;
			return Event( Event::MouseMoved, pos );
		}
		else if ( event.Type == sf::Event::MouseButtonPressed )
		{
			return Event( Event::MouseButtonPressed, ConvertToGdn( event.MouseButton.Button ) );
		}
		else if ( event.Type == sf::Event::MouseButtonReleased )
		{
			return Event( Event::MouseButtonReleased, ConvertToGdn( event.MouseButton.Button ) );
		}

		return Event( Event::Count ); // What else can I do to remove this warning? :P
	}

	Key::Code ConvertToGdn( const sf::Key::Code& key )
	{
		switch ( key )
		{
			case sf::Key::A:
				return Key::A;
			case sf::Key::B:
				return Key::B;
			case sf::Key::C:
				return Key::C;
			case sf::Key::D:
				return Key::D;
			case sf::Key::E:
				return Key::E;
			case sf::Key::F:
				return Key::F;
			case sf::Key::G:
				return Key::G;
			case sf::Key::H:
				return Key::H;
			case sf::Key::I:
				return Key::I;
			case sf::Key::J:
				return Key::J;
			case sf::Key::K:
				return Key::K;
			case sf::Key::L:
				return Key::L;
			case sf::Key::M:
				return Key::M;
			case sf::Key::N:
				return Key::N;
			case sf::Key::O:
				return Key::O;
			case sf::Key::P:
				return Key::P;
			case sf::Key::Q:
				return Key::Q;
			case sf::Key::R:
				return Key::R;
			case sf::Key::S:
				return Key::S;
			case sf::Key::T:
				return Key::T;
			case sf::Key::U:
				return Key::U;
			case sf::Key::V:
				return Key::V;
			case sf::Key::W:
				return Key::W;
			case sf::Key::X:
				return Key::X;
			case sf::Key::Y:
				return Key::Y;
			case sf::Key::Z:
				return Key::Z;

			case sf::Key::Num0:
				return Key::Number0;
			case sf::Key::Num1:
				return Key::Number1;
			case sf::Key::Num2:
				return Key::Number2;
			case sf::Key::Num3:
				return Key::Number3;
			case sf::Key::Num4:
				return Key::Number4;
			case sf::Key::Num5:
				return Key::Number5;
			case sf::Key::Num6:
				return Key::Number6;
			case sf::Key::Num7:
				return Key::Number7;
			case sf::Key::Num8:
				return Key::Number8;
			case sf::Key::Num9:
				return Key::Number9;

			case sf::Key::Up:
				return Key::UpArrow;
			case sf::Key::Left:
				return Key::LeftArrow;
			case sf::Key::Right:
				return Key::RightArrow;
			case sf::Key::Down:
				return Key::DownArrow;

			case sf::Key::Escape:
				return Key::Escape;

			case sf::Key::Comma:
				return Key::Comma;
			case sf::Key::Period:
				return Key::Period;
			case sf::Key::SemiColon:
				return Key::Semicolon;
			case sf::Key::Quote:
				return Key::SingleQuote;
			case sf::Key::Tilde:
				return Key::BackQuote;

			case sf::Key::LBracket:
				return Key::LeftBracket;
			case sf::Key::RBracket:
				return Key::RightBracket;

			case sf::Key::Slash:
				return Key::Slash;
			case sf::Key::BackSlash:
				return Key::Backslash;

			case sf::Key::Dash:
				return Key::Dash;
			case sf::Key::Equal:
				return Key::Equals;

			case sf::Key::Numpad0:
				return Key::Numpad0;
			case sf::Key::Numpad1:
				return Key::Numpad1;
			case sf::Key::Numpad2:
				return Key::Numpad2;
			case sf::Key::Numpad3:
				return Key::Numpad3;
			case sf::Key::Numpad4:
				return Key::Numpad4;
			case sf::Key::Numpad5:
				return Key::Numpad5;
			case sf::Key::Numpad6:
				return Key::Numpad6;
			case sf::Key::Numpad7:
				return Key::Numpad7;
			case sf::Key::Numpad8:
				return Key::Numpad8;
			case sf::Key::Numpad9:
				return Key::Numpad9;

			case sf::Key::Divide:
				return Key::NumpadDivide;
			case sf::Key::Multiply:
				return Key::NumpadMultiply;
			case sf::Key::Subtract:
				return Key::NumpadSubtract;
			case sf::Key::Add:
				return Key::NumpadPlus;

			case sf::Key::LControl:
			case sf::Key::RControl:
				return Key::Control;
			case sf::Key::LAlt:
			case sf::Key::RAlt:
				return Key::Alt;
			case sf::Key::LShift:
			case sf::Key::RShift:
				return Key::Shift;

			default:
				return Key::Count;
		}
	}


	Mouse::Button ConvertToGdn( const sf::Mouse::Button& button )
	{
		switch ( button )
		{
			case sf::Mouse::Left:
				return Mouse::Left;

			case sf::Mouse::Middle:
				return Mouse::Middle;

			case sf::Mouse::Right:
				return Mouse::Right;

			default:
				return Mouse::ButtonCount;
		}
	}

	char ConvertToGdn( const sf::Uint32& character )
	{
		char toReturn = character;
		return toReturn;
	}
}
